# -*- coding: utf-8 -*-
#!/usr/bin/python

##copyright 2014 Sebastian Stetter
##This file is part of the Lemonade Small Business Suite project and released under GPL v2
##http://lemonade.sebastianstetter.de

from camelot.model.fixture import Fixture
from model import *

def update_reasons():
 #opportunity rejection reasons
    reasons = [
                dict(fkey = u'missing features',  values=dict(name=u'missing features')), 
                dict(fkey = u'product quality',  values=dict(name=u'product quality')), 
                dict(fkey = u'price',  values=dict(name=u'price')), 
                dict(fkey = u'other',  values=dict(name=u'other')), 
                ]
    for u in reasons:
        Fixture.insert_or_update_fixture(OppRejectionReason, 
                                         fixture_key=u['fkey'],  
                                         values=u['values']
                                         )   
 

def update_statuses():
 #opportunuty statuses
 
    oppstatusses = [
                dict(fkey = u'open',  values=dict(name=u'open')), 
                dict(fkey = u'delayed',  values=dict(name=u'delayed')), 
                dict(fkey = u'closed won',  values=dict(name=u'closed won')), 
                dict(fkey = u'closed lost',  values=dict(name=u'closed lost')), 
                ]
    for u in oppstatusses:
        Fixture.insert_or_update_fixture(OppStatus, 
                                         fixture_key=u['fkey'],  
                                         values=u['values']
                                         )   
 
def update_lead_sources():
 #lead sources
    leadsources=[
                 dict(fkey = u'exist',  values=dict(name=u'existing customer')), 
                 dict(fkey = u'emailing',  values=dict(name=u'emailing')), 
                 dict(fkey = u'coldcall',  values=dict(name=u'coldcall')), 
                 dict(fkey = u'letter',  values=dict(name=u'letter')), 
                 dict(fkey = u'website',  values=dict(name=u'website')), 
                 dict(fkey = u'show',  values=dict(name=u'show')), 
                 dict(fkey = u'event',  values=dict(name=u'event')), 
                 dict(fkey = u'customer recommendation',  values=dict(name=u'customer recommendation')), 
                 dict(fkey = u'social media',  values=dict(name=u'social media')),
                 dict(fkey = u'other',  values=dict(name=u'other')),     
              ]
    for u in leadsources:
        Fixture.insert_or_update_fixture(Leadsource, 
                                         fixture_key=u['fkey'],  
                                         values=u['values']
                                         )   
 
def update_currencies():
 #currencies
    currencies = [
                  dict(fkey = u'EUR',  values=dict(name=u'European Euro', abbreviation=u'EUR',  symbol = u'€')), 
                  dict(fkey = u'USD',  values=dict(name=u'US Dollar', abbreviation=u'USD',  symbol = u'$')), 
                  dict(fkey = u'GBP',  values=dict(name=u'UK Pound Sterling', abbreviation=u'GBP',  symbol = u'£')), 
                  dict(fkey = u'CHF',  values=dict(name=u'Swiss Franc', abbreviation=u'CHF',  symbol = u'SFr.')), 
                  dict(fkey = u'CAD',  values=dict(name=u'Canadian Dollar', abbreviation=u'CAD',  symbol = u'$'))
                  ]
    for u in currencies:
        Fixture.insert_or_update_fixture(Currency, 
                                         fixture_key=u['fkey'],  
                                         values=u['values']
                                         )   
 
  #Industrie data
def update_industries():
    industries=[
           dict(fkey=u"agri", values = dict(name=u"Agriculture")),
           dict(fkey=u"textile", values = dict(name=u"Textile")),
           dict(fkey=u"plastics", values = dict(name=u"Plastics")),
           dict(fkey=u"metal", values = dict(name=u"Metal")),
           dict(fkey=u"electronics", values = dict(name=u"Electronics")),
           dict(fkey=u"auto", values = dict(name=u"Automotive")),
           dict(fkey=u"lumber", values = dict(name=u"Lumber")),
           dict(fkey=u"chem", values = dict(name=u"Chemicals")),
           dict(fkey=u"paper", values = dict(name=u"Paper")),
           dict(fkey=u"it", values = dict(name=u"IT ")),
           dict(fkey=u"tele", values = dict(name=u"Telecommunications")),
           dict(fkey=u"research", values = dict(name=u"Research")),
           dict(fkey=u"media", values = dict(name=u"Media")),
           dict(fkey=u"health", values = dict(name=u"Health")),
           dict(fkey=u"forest", values = dict(name=u"Forestry")),
           dict(fkey=u"education", values = dict(name=u"Education")),
           dict(fkey=u"leisure", values = dict(name=u"Leisure")),
           dict(fkey=u"food services", values = dict(name=u"Food Service Industry")),
           dict(fkey=u"food", values = dict(name=u"Food")),
           dict(fkey=u"engineering", values = dict(name=u"Engineering")),
           dict(fkey=u"printing", values = dict(name=u"Printing")),
           dict(fkey=u"advertising", values = dict(name=u"Advertising")),
           dict(fkey=u"consulting", values = dict(name=u"Consulting")), 
           dict(fkey=u"sport", values = dict(name=u"Sport")), 
           dict(fkey=u"gov", values = dict(name=u"Governemt")), 
           dict(fkey=u"public", values = dict(name=u"Public")), 
           ]
    for u in industries:
        Fixture.insert_or_update_fixture(Industry, 
                                         fixture_key=u['fkey'],  
                                         values=u['values']
                                         )   
 
def update_sales_stages():
 #SalesStage data
    stages=[
           dict(fkey=u"contact", values = dict(stage=u"contact & interest")),
           dict(fkey=u"demand", values = dict(stage=u"demand analysis")),
           dict(fkey=u"consulting", values = dict(stage=u"consulting")),
           dict(fkey=u"negotiating", values = dict(stage=u"negotiating")),
           dict(fkey=u"deal", values = dict(stage=u"deal")),
           dict(fkey=u"resume", values = dict(stage=u"resumption")),
           dict(fkey=u"satisfaction", values = dict(stage=u"satisfaction check")),
           ]
    for u in stages:
        Fixture.insert_or_update_fixture(SalesStage, 
                                         fixture_key=u['fkey'],  
                                         values=u['values']
                                         )   

def update_next_steps():
 #NextStepAction data
    actions=[
           dict(fkey=u"determine contact person", values = dict(action=u"determine contact person")),
           dict(fkey=u"make contact", values = dict(action=u"make contact")),
           dict(fkey=u"classification", values = dict(action=u"classification")),
           dict(fkey=u"demand analysis", values = dict(action=u"demand analysis")),
           dict(fkey=u"presentation", values = dict(action=u"presentation")),
           dict(fkey=u"on-site visit", values = dict(action=u"on-site visit")),
           dict(fkey=u"send sample", values = dict(action=u"send sample")),
           dict(fkey=u"test", values = dict(action=u"customer test")),           
           dict(fkey=u"proposal", values = dict(action=u"proposal")),
           dict(fkey=u"quotation", values = dict(action=u"quotation")),
           dict(fkey=u"follow up", values = dict(action=u"follow up")),
           dict(fkey=u"clarification", values = dict(action=u"clarification")),
           dict(fkey=u"deal", values = dict(action=u"deal")),
           dict(fkey=u"satisfaction", values = dict(action=u"satisfaction check"))
           ]
           
    for u in actions:
        Fixture.insert_or_update_fixture(NextStepAction, 
                                         fixture_key=u['fkey'],  
                                         values=u['values']
                                         )   
 
def update_categories():
#Categorie data
    categories=[
           dict(fkey=u"private", values = dict(name=u"private person")),
           dict(fkey=u"business", values = dict(name=u"business customer")),
           dict(fkey=u"supplier", values = dict(name=u"supplier")),
           dict(fkey=u"reseller ", values = dict(name=u"reseller")),
           dict(fkey=u"partner", values = dict(name=u"partner")),
           dict(fkey=u"opinion leader", values = dict(name=u"opinion leader")),
           dict(fkey=u"press", values = dict(name=u"press")),
           dict(fkey=u"association", values = dict(name=u"association")),
           dict(fkey=u"public institution", values = dict(name=u"public institution")),
           dict(fkey=u"non-profit organization", values = dict(name=u"non-profit organization")),
           dict(fkey=u"chamber or federation", values = dict(name=u"chamber or federation"))
           ]
           
    for u in categories:
        Fixture.insert_or_update_fixture(Category, 
                                         fixture_key=u['fkey'],  
                                         values=u['values']
                                         )

def update_units():
#Unit data
    units=[
           dict(fkey=u"pcs", values = dict(name=u"pieces",  abbreviation=u"pcs.")),
           dict(fkey=u"ltr", values = dict(name=u"liters",  abbreviation=u"l")),
           dict(fkey=u"g", values = dict(name=u"gramms",  abbreviation=u"g")),
           dict(fkey=u"ve", values = dict(name=u"unit",  abbreviation=u"u")),
           dict(fkey=u"m", values = dict(name=u"meters",  abbreviation=u"m")),
           dict(fkey=u"cm", values = dict(name=u"centimeters",  abbreviation=u"cm")),
           dict(fkey=u"sqm", values = dict(name=u"square meters",  abbreviation=u"sqm")), 
           dict(fkey=u"in", values = dict(name=u"inches",  abbreviation=u'in')), 
           dict(fkey=u"ft", values = dict(name=u"feet",  abbreviation=u'ft')), 
           dict(fkey=u"lbs", values = dict(name=u"pound",  abbreviation=u"lbs")), 
           dict(fkey=u"gal", values = dict(name=u"gallon",  abbreviation=u'gal'))
           ]
           
    for u in units:
        Fixture.insert_or_update_fixture(Unit, 
                                         fixture_key=u['fkey'],  
                                         values=u['values']
                                         )


def update_product_types():
#ProductType data
    types=[
           dict(fkey=u"P", values = dict(name=u"product",  abbreviation=u"prod.")),
           dict(fkey=u"S", values = dict(name=u"service",  abbreviation=u"serv.")),
           dict(fkey=u"C", values = dict(name=u"contract",  abbreviation=u"cont.")),
           dict(fkey=u"subs", values = dict(name=u"subscription",  abbreviation=u"subs."))
           ]
           
    for u in types:
        Fixture.insert_or_update_fixture(ProductType, 
                                         fixture_key=u['fkey'],  
                                         values=u['values']
                                         )
                                         

def update_contact_mechanism_types():
#ContactMechanismType data
    types=[
           dict(fkey=u"private", values = dict(type=u"private")),
           dict(fkey=u"business", values = dict(type=u"business")),
           ]
           
    for u in types:
        Fixture.insert_or_update_fixture(ContactMechanismType, 
                                         fixture_key=u['fkey'],  
                                         values=u['values']
                                         )
                                         

def update_tax_keys():
#TaxKey data
    keys=[
           dict(fkey=u"M19", values = dict(abbreviation='M19', name=u"value added tax 19%",  factor=19)),
           dict(fkey=u"M7", values = dict(abbreviation='M7', name=u"value added tax 7%",   factor=7)),
           dict(fkey=u"M0", values = dict(abbreviation='M0', name=u"value added tax 0%",   factor=0)),
           ]
           
    for u in keys:
        Fixture.insert_or_update_fixture(TaxKey, 
                                         fixture_key=u['fkey'],  
                                         values=u['values']
                                         )
#TaxKey data
    translations=[
           dict(fkey=u"deM19", values = dict(language='de_DE', name=u"MwSt. 19%",  tax_key_id=1)),
           dict(fkey=u"deM7", values = dict(language='de_DE',  name=u"MwSt. 7%",   tax_key_id=2)),
           dict(fkey=u"deM0", values = dict(language='de_DE',  name=u"MwSt. 0%",   tax_key_id=3)),
           ]
           
    for u in translations:
        Fixture.insert_or_update_fixture(TaxKeyTranslation, 
                                         fixture_key=u['fkey'],  
                                         values=u['values']
                                         )
                                                                                  

def update_users():
#User data
    users = [
            dict(fkey=u"stetter", values = dict(username=u'sebste', firstname=u"Sebastian",  lastname=u"Stetter")),
            dict(fkey=u"müller", values = dict(username=u'hmueller', firstname=u"Horst",  lastname=u"Müller.")),
            dict(fkey=u"sonne", values = dict(username=u'gsonne', firstname=u"Gabrielle",  lastname=u"Sonnenschein.")),
           ]
    for u in users:
        Fixture.insert_or_update_fixture(User, 
                                         fixture_key=u['fkey'],  
                                         values=u['values']
                                         )

def update_payment_terms():
#PaymentTerm data
    terms = [
            dict(fkey=u"immediately", values = dict(name=u'immediately', days=3,  text=u"Payment on receipt of invoice.")),
            dict(fkey=u"10net", values = dict(name=u'10 days strictly net', days=10,  text=u"Invoice amount is payable within #DAYS days (until #DUEDATE).")),
            dict(fkey=u"30net", values = dict(name=u'30 days strictly net', days=30,  text=u"Invoice amount is payable within #DAYS days (until #DUEDATE)."))
           ]
    for u in terms:
        Fixture.insert_or_update_fixture(PaymentTerm, 
                                         fixture_key=u['fkey'],  
                                         values=u['values']
                                         )

def update_contact_mechanisms():
#ContactMechanism data    
    mechanisms = [
            dict(fkey=u"a", values = dict(customer_id=1, is_prefered=True, contact_mechanism_type_id=1,  mechanism=("email","heinz.schmidt@haeberle.ru"))),
            dict(fkey=u"b", values = dict(customer_id=1, is_prefered=True,  contact_mechanism_type_id=1,  mechanism=('phone', '1234567'))),
            dict(fkey=u"c", values = dict(customer_id=1, Is_prefered=False, contact_mechanism_type_id=1,  mechanism=("mobile","1234567"))),
            dict(fkey=u"d", values = dict(customer_id=2, is_prefered=True, contact_mechanism_type_id=2,  mechanism=("email","margarete.vogel@example.com"))),
            dict(fkey=u"e", values = dict(customer_id=2, is_prefered=True,  contact_mechanism_type_id=2,  mechanism=('phone', '1234567'))),
            dict(fkey=u"f", values = dict(customer_id=2, Is_prefered=False, contact_mechanism_type_id=2,  mechanism=("mobile","1234567"))),
           ]
    for u in mechanisms:
        Fixture.insert_or_update_fixture(ContactMechanism, 
                                         fixture_key=u['fkey'],  
                                         values=u['values']
                                         )

def update_shipping_methods():
    methods = [
            dict(fkey=u"dhl_paket", values = dict(name=u'Paket', service=u"DHL")),
            dict(fkey=u"ups_paket", values = dict(name=u'Sperrgut', service=u"UPS")), 
            dict(fkey=u"post_Warensendung", values = dict(name=u'Warensendung', service=u"Deutsche Post")),
           ]
    for u in methods:
        Fixture.insert_or_update_fixture(ShippingMethod, 
                                         fixture_key=u['fkey'],  
                                         values=u['values']
                                         )
    
    
def update_document_types():
#DocumentType data
    types = [
            dict(fkey=u"contract", values = dict(type=u'contract', description=u"contract documents")),
            dict(fkey=u"quotation", values = dict(type=u'quotation', description=u"quotations")),
            dict(fkey=u"letter", values = dict(type=u'letter', description=u"letter")), 
            dict(fkey=u"datasheet", values = dict(type=u'datasheet', description=u"datasheet")), 
            dict(fkey=u"prod info", values = dict(type=u'product information', description=u"product information"))
           ]
    for u in types:
        Fixture.insert_or_update_fixture(DocumentType, 
                                         fixture_key=u['fkey'],  
                                         values=u['values']
                                         )


def update_voucher_types():
#VoucherType data

    vouchertype_mapper = orm.class_mapper( VoucherType )
    icon_property = vouchertype_mapper.get_property( 'icon' )
    storage = icon_property.columns[0].type.storage
    
    default_template_path=unicode( os.path.abspath(os.path.join(resource_filename(lemonade.__name__, 'templates'), 'voucher.html')) )

    types = [
            dict(fkey=u"quote", values = dict(name=u'Quote', abbreviation=u"QUO", prefix=u"QUO", first_voucher_number=100,  icon='quotation.png',  use_address='billing address',  default_template=default_template_path,  default_pre_text=u'Thank you for your enquiry', default_post_text=u'This offer will be valid for 14 days. We are looking forward to receiving your order. Kind regards, The Lemonade Stand team')),
            dict(fkey=u"order", values = dict(name=u'Order Confirmation', abbreviation=u"ORD", prefix=u"ORD", first_voucher_number=100,  icon='order-confirmation.png', use_address='billing address',  default_template=default_template_path,  default_pre_text=u'Thank you for your order', default_post_text=u'We will take great care to meet your expectations. Kind regards, The Lemonade Stand team')),
            dict(fkey=u"shipp", values = dict(name=u'Shipping Note', abbreviation=u"SN", prefix=u"SN", first_voucher_number=100,  icon='shipping-note.png', use_address='shipping address',  default_template=default_template_path, default_post_text=u'Please check the packaging and contents of your delivery for visual damages immediately and report them directely to the logistics service provider')),
            dict(fkey=u"proforma", values = dict(name=u'Proforma Invoice', abbreviation=u"PINV", prefix=u"P-INV", first_voucher_number=100, icon='proforma-invoice.png', use_address='billing address',  default_template=default_template_path,  default_pre_text=u'Thank you again for your valued trust in the quality of our product and for your order.', default_post_text=u'Kind regards, The Lemonade Stand team')),            
            dict(fkey=u"invoice", values = dict(name=u'Invoice', abbreviation=u"INV", prefix=u"INV", first_voucher_number=100, icon='invoice.png', use_address='billing address',  default_template=default_template_path, default_pre_text=u'Thank you again for your valued trust in the quality of our product and for your order.', default_post_text=u'Kind regards, The Lemonade Stand team')),
            dict(fkey=u"credit", values = dict(name=u'Credit Note', abbreviation=u"CRE", prefix=u"CRE", first_voucher_number=100, icon='credit-note.png', use_address='billing address',  default_template=default_template_path)),
            dict(fkey=u"reminder", values = dict(name=u'Overdue Notice', abbreviation=u"ODN", prefix=u"ODN", first_voucher_number=100, icon='overdue-notice.png', use_address='billing address',  default_template=default_template_path, default_pre_text=u'It was our pleasure to fullfill your order. nfortunately we have not received the payment for the positions listed below, yet.', default_post_text=u'If you have not paid, yet, please make the payment immediately. Thank you very much. Kind regards, The Lemonade Stand team')),
           ]
    
    for u in types:
        myvalues = u['values']
        ico=myvalues['icon']
        myvalues['icon']= storage.checkin( unicode( os.path.abspath(os.path.join(resource_filename(lemonade.__name__, 'icons'), ico)) ) )
        Fixture.insert_or_update_fixture(VoucherType, fixture_key=u['fkey'],  values=myvalues)

# No ORM class 
#    types = [
#            dict(fkey=u"quote_order", values = dict(voucher_type_id=1, successor_voucher_types_id=2)),
#            dict(fkey=u"quote_proforma_invoice", values = dict(voucher_type_id=1, successor_voucher_types_id=4)),
#            
#            dict(fkey=u"quote_shipp", values = dict(voucher_type_id=1, successor_voucher_types_id=3)),            
#            dict(fkey=u"order_shipp", values = dict(voucher_type_id=2, successor_voucher_types_id=3)),
#            dict(fkey=u"proforma_shipp", values = dict(voucher_type_id=4, successor_voucher_types_id=3)),
#            dict(fkey=u"invoice_shipp", values = dict(voucher_type_id=5, successor_voucher_types_id=3)),
#            
#            dict(fkey=u"quote_invoice", values = dict(voucher_type_id=1, successor_voucher_types_id=5)),
#            dict(fkey=u"proforma_invoice", values = dict(voucher_type_id=4, successor_voucher_types_id=5)),
#            dict(fkey=u"shipp_invoice", values = dict(voucher_type_id=3, successor_voucher_types_id=5)),
#        
#            dict(fkey=u"invoice_cred", values = dict(voucher_type_id=5, successor_voucher_types_id=6)),
#            dict(fkey=u"invoice_reminder", values = dict(voucher_type_id=5, successor_voucher_types_id=7)),
#            dict(fkey=u"reminder_reminder", values = dict(voucher_type_id=7, successor_voucher_types_id=7)),
#            
#           ]
#    for u in types:
#        Fixture.insert_or_update_fixture(SuccessorVoucherTypes, 
#                                         fixture_key=u['fkey'],  
#                                         values=u['values']
#                                         )

def update_customers():
#############################CREATE A Customer###########################################
    customers = [
            dict(fkey=u"kunde_schmidt", values = dict(
                                                      matchcode=u"Heinz Schmidt, Fa. Häberle KG", 
                                                      supplyer_id=u"0815-a", 
                                                      locked=False, 
                                                      company_name=u'Häberle & Co.KG', 
                                                      company_additional=u'Kurzwaren', 
                                                      
                                                      person_salutation=u"Herr", 
                                                      person_letter_salutation=u'Sehr geehrter Herr', 
                                                      person_firstname=u'Heinz', 
                                                      person_initials=u"R.", 
                                                      person_lastname=u'Schmidt', 
                                                      person_nickname=u"Schmittchen", 
                                                      person_spouses_name=u"Sieglinde Schmidt", 
                                                      person_title="Dr.", 
                                                      person_birthday=datetime.date(year=1955,month=5,day=2), 
                                                      person_language=u'de_DE', 
                                                      person_department=u'Einkauf', 
                                                      person_profession=u'Betriebswirt', 

                                                      vat_id = u'DE0000000000000', 
                                                      industry_id=2, 
                                                      iban=u'DE0000000000000', 
                                                      bic=u'SOLADESKNZ001', 

                                                      payment_rating=4, 
                                                      payment_term_id= 1, 
                                                      notes=u'Super Kunde!'
                                                      )),
            dict(fkey=u"kunde_Vogel", values = dict(
                                                      matchcode=u"Margarete Vogel, Fa. Kohler GmbH", 
                                                      supplyer_id=u"abcdefg", 
                                                      locked=False, 
                                                      company_name=u'Kohler GmbH', 
                                                      company_additional=u'Autoteile', 
                                                      
                                                      person_salutation=u"Frau", 
                                                      person_letter_salutation=u'Sehr geehrte Frau', 
                                                      person_firstname=u'Margarete', 
                                                      person_lastname=u'Vogel', 
                                                      person_initials=u"Renate", 

                                                      person_nickname=u"Vögele", 
                                                      person_spouses_name=u"Heinz Müller", 
                                                      person_title="Prof.", 
                                                      person_birthday=datetime.date(year=1958,month=2,day=13), 
                                                      person_language=u'en_US', 
                                                      person_department=u'Einkauf', 
                                                      person_profession=u'Wirtschaftswissenschaftlerin', 

                                                      vat_id = u'DE0000000000001', 
                                                      industry_id=6, 
                                                      iban=u'DE0000000000000', 
                                                      bic=u'SOLADESKNZ001', 

                                                      payment_rating=5, 
                                                      payment_term_id= 2, 
                                                      notes=u'Awesome Service!'
                                                      )),
           ]
    for u in customers:
        Fixture.insert_or_update_fixture(Customer, 
                                         fixture_key=u['fkey'],  
                                         values=u['values']
                                         )
    

    addresses = [
            dict(fkey=u"address_kunde_schmidt1", values = dict(street_box=u'Lange Strasse 123',  zip=u"12345",  city=u'Glückstadt',  region='BW',  country=u'Deutschland',  is_billing_address=True,  is_shipping_address = True, is_prefered_address = True,  customer_id=1)),
            dict(fkey=u"address_kunde_schmidt2", values = dict(street_box=u'Kleegasse 8',  zip=u"12347",  city=u'Glückstadt',  region='BW',  country=u'Deutschland',  is_billing_address=False,  is_shipping_address = False,  customer_id=1)),
            dict(fkey=u"address_kunde_schmidt3", values = dict(street_box=u'Lange Strasse 123',  zip=u"12345",  city=u'Glückstadt',  region='BW',  country=u'Deutschland',  is_billing_address=False,  is_shipping_address = False,  customer_id=1)),
            dict(fkey=u"address_kunde_Vogel1", values = dict(street_box=u'Kurze Strasse 1',  zip=u"12345",  city=u'Glückstadt',  region='BW',  country=u'Deutschland',  is_billing_address=True,  is_shipping_address = True,  is_prefered_address = True,customer_id=2)),
            dict(fkey=u"address_kunde_Vogel2", values = dict(street_box=u'Kastanienallee 1',  zip=u"12345",  city=u'Glückstadt',  region='BW',  country=u'Deutschland',  is_billing_address=False,  is_shipping_address = False,  customer_id=2)),
            dict(fkey=u"address_kunde_Vogel3", values = dict(street_box=u'Main Street 142',  zip=u"0000",  city=u'Halifax',  region='Nova Scotia',  country=u'Canada',  is_billing_address=True,  is_shipping_address = True,  customer_id=2)),
           ]
    for u in addresses:
        Fixture.insert_or_update_fixture(Address, 
                                         fixture_key=u['fkey'],  
                                         values=u['values']
                                         )
                                         

#############################END CREATE Customer###########################################

def update_products():
#sample product data

    products=[
              dict(fkey=u'ponny', values= dict(
                                               product_number = 1, 
                                               product_type = ProductType.query.filter_by(name=u'product').first(), 
                                               product_name = u'Ponny, spotted', 
                                               product_text_short = u'little spotted geschecktes pony', 
                                               product_text_long = u'little spotted geschecktes pony for feeding and loving', 
                                               stock = 10, 
                                               min_stock = 1, 
                                               price = 500, 
                                               incl_tax = False, 
                                               currency = Currency.query.filter_by(name = u'European Euro').first(), 
                                               tax_key = TaxKey.query.filter_by(abbreviation=u'M19').first(), 
                                               unit = Unit.query.filter_by(name=u'pieces').first(),  
                                               hazmat =False, 
                                               weight =300
                                               )
                                               ), 
              dict(fkey=u'lemonade', values= dict(
                                               product_number = 2, 
                                               product_type = ProductType.query.filter_by(name=u'product').first(), 
                                               product_name = u'Lemonade', 
                                               product_text_short = u'Finest Lemonade', 
                                               product_text_long = u'Finest Lemonade - 100% juice', 
                                               stock = 10, 
                                               min_stock = 1, 
                                               price = 1.75, 
                                               incl_tax = True, 
                                               currency = Currency.query.filter_by(name = u'European Euro').first(), 
                                               tax_key = TaxKey.query.filter_by(abbreviation=u'M7').first(), 
                                               unit = Unit.query.filter_by(name=u'liters').first(),  
                                               hazmat =False, 
                                               weight =1
                                               ) 
                    )
              ]
    for u in products:
        Fixture.insert_or_update_fixture(Product, 
                                         fixture_key=u['fkey'],  
                                         values=u['values']
                                         )
                                         
    
def update_preferences():
    #sample data for preferences
    
    preferrences_mapper = orm.class_mapper( Preferences )
    logo_property = preferrences_mapper.get_property( 'logo' )
    storage = logo_property.columns[0].type.storage
    stored_file = storage.checkin( unicode( os.path.abspath(os.path.join(resource_filename(lemonade.__name__, 'templates'), 'lemonadelogo.png')) ) )
    
    Fixture.insert_or_update_fixture(Preferences, 
                                         fixture_key="default_prefs",  
                                         values=dict(
                                                       logo=stored_file, 
                                                       company_name = u"My Lemonade Stand", 
                                                       company_additional =  u"finest natural lemonade", 
                                                       company_address1 = u"Refreshment Lane 180", 
                                                       company_address2 = u"Grannie's Little House", 
                                                       company_zip =  u"00000", 
                                                       company_city =  u"Citrus Hill", 
                                                       company_country =  u"Beveragia", 
                                                       company_email =  u"mail.example.com", 
                                                       company_website = u"www.example.com", 
                                                       company_vat_id = u"BV1223346879", 
                                                       company_bank = u"Citrus Hill Park Bank", 
                                                       company_BIC =  u"SOLABVS01CHZ", 
                                                       company_IBAN = u"DE123456789123465789", 
                                                       company_legal_form = u"Inc.", 
                                                       company_phone = u"123456789", 
                                                       company_fax =  u"123456789", 
                                                       company_legal_info1= u"Handelsregister", 
                                                       company_legal_info2= u"Amtsgericht Citrus Hill", 
                                                       company_legal_info3= u"HRB12345", 
                                                       
                                                       #imap server preferences
                                                       imap_server = u"imap.example.com", 
                                                       imap_user = u"imapuser", 
                                                       imap_password = u"imappassword", 
                                                       imap_use_tls =  True, 
                                                       imap_fetch_frequency = 10, 
                                                       
                                                       #telephony preferences
                                                       telephony_system="Lemonade Android Connector", 
                                                       telephony_system_call_string = u"python ~/Python/sipgate/click2call.py -u #user -p #password -n #number",
                                                       telephony_default_user = u"sipuser", 
                                                       telephony_default_password = u"sippassword", 
                                                       
                                                       android_device_ip = u'192.168.1.3', 
                                                       android_device_port = 50505, 
                                                       android_device_secret = u'secret', 
                                                       
                                                       #currency and localization preferences
                                                        default_currency = Currency.query.filter_by(abbreviation=u"EUR").first(), 
                                                        default_language=u'de_DE', 
                                                        first_customer_number = 100, 
                                                        printer_margin_left = 24, 
                                                        printer_margin_top = 15, 
                                                        printer_margin_right = 24, 
                                                        printer_margin_bottom =  5, 
                                                        printer_margin_unit = u'Millimeter', 
                                                        printer_page_size = u'A4', 
                                                        printer_page_orientation = u'Portrait', 
                                                       )
                                         )
def update_fixtures():
    update_reasons()
    update_statuses()
    update_lead_sources()
    update_currencies()
    update_industries()
    update_sales_stages()
    update_next_steps()
    update_units()
    update_product_types()
    update_contact_mechanism_types()
    update_tax_keys()
    update_users()
    update_payment_terms()
    update_contact_mechanisms()
    update_document_types()
    update_customers()
    update_products()
    update_statuses()
    update_shipping_methods()
    

    update_voucher_types()
    update_preferences()
    update_categories()
